package com.qf.admin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.admin.domain.Orders;
import com.qf.admin.mapper.OrdersMapper;
import com.qf.admin.pojo.QueryOrder;
import com.qf.admin.service.IOrdersService;
import com.qf.commons.TableData;
import com.qf.pojo.ProcessLog;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderServiceImpl implements IOrdersService {

    private OrdersMapper ordersMapper;

    public OrderServiceImpl(OrdersMapper ordersMapper) {
        this.ordersMapper = ordersMapper;
    }

    @Override
    public TableData<Orders> getAllOrders(QueryOrder queryOrder, Integer offset, Integer limit) {

        String orderNumber = queryOrder.getOrderNumber();
        if (null != orderNumber && !"".equals(orderNumber.trim())) {
            queryOrder.setOrderNumber("%" + orderNumber + "%");
        }

        String getGoods = queryOrder.getGoods();
        if (null != getGoods && !"".equals(getGoods.trim())) {
            queryOrder.setGoods("%" + getGoods + "%");

        }

        Page<Orders> page = PageHelper.offsetPage(offset, limit);

        ordersMapper.getAllOrder(queryOrder);

        TableData<Orders> tableData = new TableData<>();
        tableData.setRows(page.getResult());
        tableData.setTotal((int) page.getTotal());

        return tableData;
    }

    @Override
    public Orders getOrderUserById(Integer id) {
        Orders orderUserById = ordersMapper.getOrderUserById(id);
        return orderUserById;
    }

    @Override
    public List<Orders> getUserAddress(Integer id) {
        List<Orders> getUserAddress = ordersMapper.getUserAddress(id);
        return getUserAddress;
    }

    @Override
    public void updateAddress(Integer aid, Integer uid) {
        ordersMapper.updateAddress(aid,uid);
    }

    @Override
    public TableData<ProcessLog> getProcessLog(Integer offset, Integer limit) {
        Page<ProcessLog> page = PageHelper.offsetPage(offset, limit);
        ordersMapper. getProcessLog(offset,limit);
        TableData<ProcessLog> gettableData = new TableData<>();
        gettableData.setRows(page.getResult());
        gettableData.setTotal((int) page.getTotal());
        return gettableData;
    }




}
